package com.coderman.common.starter.nacos.paperwork.listener;

import com.coderman.common.starter.nacos.paperwork.config.NacosPaperTextProperties;
import com.coderman.common.starter.nacos.paperwork.service.PaperTextConfigListener;
import com.coderman.common.starter.nacos.paperwork.service.PaperTextConfigListenerImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * Description: spring 容器启动监听器，容器启动成功之后链接nacos获取配置数据
 * date: 2020/10/14
 *
 * @author fanchunshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Order(value = 1001)
@Component
public class SpringPaperTextConfigListener implements ApplicationListener<ApplicationStartedEvent> {
    private Logger logger = LoggerFactory.getLogger(SpringPaperTextConfigListener.class);

    @Autowired
    private NacosPaperTextProperties nacosDataProperties;

    @Autowired
    private PaperTextConfigListener configListener;

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {


        try {
            logger.info("应用启动成功,准备初始化业务配置数据:PaperTextConfig.......................");
            configListener.addListener(nacosDataProperties.getDataIDArr(),nacosDataProperties.getGroupIDArr());
            logger.info("应用启动成功,初始化业务配置数据成功:PaperTextConfig.......................");
        } catch (Exception e) {
            logger.error("初始化远程配置失败:PaperTextConfig",e);
        }
    }
}
